#include<iostream>
#include<cstring>
using namespace std;
const int N = 2e5 + 10, M = N * 2, mod = 1e4 + 7;
int h[N], e[M], ne[M], idx;
int w[N];
int n, m;
int ans1, ans2;
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void dfs(int u, int fa, int g)
{
	int maf = 0, mas = 0, sum1 = 0, sum2 = 0;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j == fa)continue;
		sum1 = (sum1 + w[j]) % mod;
		sum2 = (sum2 + w[j] * w[j] % mod) % mod;
		if (w[j] > maf) {
			mas = maf;
			maf = w[j];
		}
		else if (w[j] > mas) {
			mas = w[j];
		}
		dfs(j, u, fa);
	}
	ans1 = max(ans1, max(mas * maf, w[g] * w[u]));
	ans2 = (ans2 + (sum1 * sum1 % mod - sum2) % mod +
		(w[g] * w[u] * 2 % mod)) % mod;
}
int main()
{
	cin >> n;
	memset(h, -1, sizeof(h));
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		add(a, b);
		add(b, a);
	}
	for (int i = 1; i <= n; i++)cin >> w[i];
	dfs(1, 0, 0);
	cout << ans1 << " " << ans2 % mod << endl;
	return 0;
}